//
//  ImagesStateView.m
//  sensen_ios
//
//  Created by mc on 16/4/9.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ImagesStateView.h"

@implementation ImagesStateView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = rgba(226, 227, 228, 1);
        NSArray * array = @[@"灯光照明", @"冲浪水泵", @"紫外线灯", @"备用电源"];
        
        
        NSInteger interval = 10;
        NSInteger width = (SCREEN_WIDTH - 8 * interval) / 4;
        NSInteger heigth = 10;
        for (int i = 0; i < 4; i++) {
            UIImageView * view = [[UIImageView alloc] initWithFrame:CGRectMake(interval + (interval * 2 + width) * i, heigth, width, width)];
            view.tag = 100 + i;
            [self addSubview:view];
            
            UILabel *lable = [[UILabel alloc] init];
            [self addSubview:lable];
            
            [lable mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(view.mas_centerX);
                make.top.equalTo(view.mas_bottom).offset(interval);
                make.size.mas_equalTo(CGSizeMake(width, interval * 2));
            }];
            
            lable.text = array[i];
            lable.textAlignment = NSTextAlignmentCenter;
            lable.textColor = [UIColor grayColor];
            
            if (SCREEN_WIDTH < 375) {
                lable.adjustsFontSizeToFitWidth = YES;
            }
           
        }
        
        
        
    }
    return self;
}

- (void)setStateArray:(NSMutableArray *)stateArray{
    UIImageView * view1 = [self viewWithTag:100];
    UIImageView * view2 = [self viewWithTag:101];
    UIImageView * view3 = [self viewWithTag:102];
    UIImageView * view4 = [self viewWithTag:103];
    
//    //备用电源状态
//    view1.image = [UIImage imageNamed:@"设备报警设定_14"];
//    //紫外线灯
//    view2.image = [UIImage imageNamed:@"设备报警设定_17"];
//    //冲浪水泵
//    view3.image = [UIImage imageNamed:@"设备报警设定_21"];
//    //灯光照明
//    view4.image = [UIImage imageNamed:@"设备报警设定_23"];

    
    //备用电源状态
    view4.image = [UIImage imageNamed:([stateArray[3] integerValue] < 1 ? @"设定_28":@"设备报警设定_23")];
    //紫外线灯
    view3.image = [UIImage imageNamed:([stateArray[2] integerValue] < 1 ? @"设定_26":@"设备报警设定_21")];
    //冲浪水泵
    view2.image = [UIImage imageNamed:([stateArray[1] integerValue] < 1 ? @"设定_24":@"设备报警设定_17")];
    //灯光照明
    view1.image = [UIImage imageNamed:([stateArray[0] integerValue] < 1 ? @"设定_22":@"设备报警设定_14")];
    
    
    NSLog(@"最终   灯光状态 ＝ %@， 水泵状态 ＝ %@，  紫外线 ＝ %@ ， 备用电源 ＝ %@", stateArray[0], stateArray[1], stateArray[2], stateArray[3]);
    
    
}


@end
